import { createApp } from 'vue'
import App from './App.vue'
//导入axios框架
import Axios from 'axios'
//导入bootstrap样式
import 'bootstrap/dist/css/bootstrap.min.css'
//导入ElementPlus框架
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
//导入 router框架
import Router from './router/index.js'

//导入echarts框架
import Echarts from "vue-echarts";
import 'echarts';

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus)
app.use(Router)
app.mount('#app')
app.component('Echarts',Echarts)


let token = '<PASSWORD>';
setStorage.setItem({value:token,name:'token',expires:60000})//存储token 过期时间是毫秒 此处是一分钟
token = setStorage.getItem('token')//获取token

router.beforeEach((to, from, next) => {
    // 1.如果访问的是登录页面（无需权限），直接放行
    if (to.path === '/' || to.path === '/register' || to.path === '/found' || to.path === '/phone') return next()
    // 2.如果访问的是有登录权限的页面，先要获取token
    const tokenStr = window.sessionStorage.getItem('token')
    // 2.1如果token为空，强制跳转到登录页面；否则，直接放行
    if (!tokenStr) {
        alert("请登录")
        return next('/')
    }
    next();
})